package com.wangsd.web.coupon.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wangsd.common.basicbean.Result;
import com.wangsd.web.MyController;
import com.wangsd.web.coupon.entity.MemberCoupon;
import com.wangsd.web.coupon.service.MemberCouponService;
import com.wangsd.web.sys.entity.SysUser;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author generator
 * @since 2019-09-26
 */
@RestController
@RequestMapping("/coupon/memberCoupon")
public class MemberCouponController extends MyController {

    @Autowired
    MemberCouponService memberCouponService;

    @PostMapping("/selectList/{pageNum}/{pageSize}")
    @ApiOperation(value = "查询优惠券列表", notes = "查询优惠券列表", httpMethod = "POST")
    public Result selectList(@PathVariable Integer pageNum,
                             @PathVariable Integer pageSize,
                             @RequestBody @ApiParam(name = "coupon", value = "传入json格式") MemberCoupon coupon) {
        SysUser loginUser = getUserInfo();

        String code = loginUser.getCode();
        IPage<MemberCoupon> resultList = memberCouponService.selectList(code, pageNum, pageSize, coupon);
        Map statistics = memberCouponService.selectListStatisticsXml(code, pageNum, pageSize, coupon);
        Map map = new HashMap();
        map.put("pageInfo",resultList);
        map.put("statistics",statistics);
        return Result.success(map);
    }
}

